<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    #fujian .edittits{margin-left: 20px}
</style>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建参建单位</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>单位名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>单位类型</label>
                        <div class="layui-input-block">
                            <select id="type" name="type" lay-filter="type"></select>
                            <p class="error" id="type_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">企业资质</label>
                        <div class="layui-input-block">
                            <input type="text" name="zizhi" id="zizhi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">企业法人</label>
                        <div class="layui-input-block">
                            <input type="text" name="faer" id="faer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">法人电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="fatel" id="fatel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-block">
                            <input type="text" name="lianer" id="lianer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="liantel" id="liantel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div id="fujian">
                <?php include '../public/upinfo.php'?>
            </div>
        </div>
    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });

    $("#fujian .edittits").html('相关附件（请附加参建单位相关资料）')

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();


        facade.ajax({type: 'get', url: ask_dealcom_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;

                var type_str = '<option value="">请选择</option>';
                var type = res.data.type;
                for (var key in type){
                    type_str += '<option value="'+key+'">'+type[key]+'</option>';
                }
                $("#type").html(type_str);


                public_upload_file_load('upload_files');
                render_from();
            }
        });


        form.on('select(type)', function(data){
            if(data.value == ''){
                $('#type_error').show().text('请选择');
                $('#type_error').parent().find('input').addClass('select_error');
            }else{
                $('#type_error').hide();
                $('#type_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            if(data.field.type == ''){
                $('#type_error').show().text('请选择');
                $('#type_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#type_error').hide();
                $('#type_error').parent().find('input').removeClass('select_error');
            }

            if(!validRes){return false;}

            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_dealcom_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
